<template>
  <div class="person">
    <h2>一辆{{ car.brand }}车，价值{{ car.price }}万</h2>
    <button @click="changeBrand">升级</button>
    <button @click="changePrice">加价</button>
    <button @click="changeCar">换车</button>
    <hr>
    <h2>当前求和为：{{ sum }}</h2>
    <button @click="changeSum">sum+1</button>
  </div>
</template>

<script setup lang="ts" name="Person">
    import {ref,reactive} from 'vue'
    let car = reactive({brand:'奔驰' ,price:100})
    let sum = ref(0)
    function changeBrand(){
        car.brand ='奔驰E'
    }
    function changePrice(){
        car.price += 10
    }
    function changeCar(){
        //reactive定义的对象不能直接修改整个对象
        //car = {brand:'奥迪',price:1}
        //可通过如下方法实现
        Object.assign(car,{brand:'奥迪',price:1})

        //ref定义的对象能直接修改整个对象
        // car.value = {brand:'奥迪',price:1}

        
    }
    function changeSum(){
        sum.value +=1    
    }
</script>

<style scoped>
    .person{
        background-color: skyblue;
        box-shadow: 0 0 10px;
        border-radius: 10px;
        padding: 20px;
    }
    button{
        margin: 0 5px
    }
    li{
        font-size: 20px;
    }
</style>